﻿using System;
using System.Runtime.Serialization;

namespace Pfz.DynamicObjects.Internal
{
	[Serializable]
	internal class DuckReference:
		IObjectReference
	{
		public DuckReference(SerializationInfo info, StreamingContext context)
		{
			object realObject = info.GetValue("Target", typeof(object));
			Type type = (Type)info.GetValue("CastType", typeof(Type));
			object securityToken = info.GetValue("SecurityToken", typeof(object));

			_value = DuckCaster.Cast(realObject, type, securityToken);
		}

		private readonly object _value;
		public object GetRealObject(StreamingContext context)
		{
			return _value;
		}
	}
}
